﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Active.Core.State;
using Active.Core;

public partial class User_Controls_OrderStateControl : System.Web.UI.UserControl
{
    

    protected void Page_Load(object sender, EventArgs e)
    {
        ////当已提交或已存在付款信息时, 不能修改已有的媒介订单
        ////修改删除以前所有的付款信息, 才可以修改
        //if (CurrentOrder.StateValue == OrderStateValue.MediaEmployeeWoring 
        //    && CurrentOrder.PayoutRecords.Length > 0)
        //{
        //    this.ClearAdvanceAndBrokerageLinkButton.Visible = true;
        //}
    }

    //protected void ClearAdvanceAndBrokerageLinkButton_Click(object sender, EventArgs e)
    //{
    //    Guid userId = (Guid)Membership.GetUser().ProviderUserKey;
        
    //    CurrentOrder.ClearPayoutInfos("从媒介订单中退回");

    //    Response.Redirect(Request.RawUrl);
    //}

    #region Business Methods

    protected Order GetOrder()
    {
        string idString = Request.QueryString["id"];
        object businessObj = Session["CurrentObj"];
        if (businessObj == null || !(businessObj is Order)
            || (!IsPostBack && !((Order)businessObj).Id.ToString().Equals(idString)))
        {
            try
            {
                if (!string.IsNullOrEmpty(idString))
                {
                    businessObj = Order.GetOrder(int.Parse(idString));
                }
                else
                {
                    Response.Redirect("~/Bill");
                }
                Session["CurrentObj"] = businessObj;
            }
            catch (System.Security.SecurityException)
            {
                Response.Redirect("~/Bill");
            }
        }
        return businessObj as Order;
    }

    #endregion

    protected void OrderDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
    {
        e.BusinessObject = GetOrder();
    }
}
